#include "CppHeaderCodeGenerator.h"
#include "CppSourceCodeGenerator.h"

int main( int argc, char* argv[] )
{
	/**
	* parser typedef file
	*/
	xml_document doc;
	xml_parse_result result = doc.load_file(argv[1]);	
	
	if( result ) {
		cout << "Type file[" << argv[1] << "] parsed with no errors." << endl;
	}else {
		cout << "Type file[" << argv[1] << "] parsed with error, attr value: [" << doc.child("node").attribute("attr").value() << "]\n";
		cout << "Error description: " << result.description() << "\n";
		return -1;
	}

	xml_node types = doc.root().first_child();

	/**
	* generate header files and stub source file
	*/
	int ret = 0;

	while( true )
	{
		cout << "Generate c++ header file." << endl;
		CppHeaderGenerator headerGen(types);
		if( 0==headerGen.Initial(argv[1]) ) {
			if( 0!=headerGen.Generate() )
				ret = -2;
			if( 0!=headerGen.Finalize() )
				ret = -2;
		} else {
			ret = -2;
		}
		if( 0!=ret ) {
			cout << "Failed to generate c++ header file." << endl;
			break;
		}

		cout << "Generate c++ source file." << endl;
		CppSourceGenerator sourceGen(types);
		if( 0==sourceGen.Initial(argv[1]) ) {
			if( 0!=sourceGen.Generate() )
				ret = -3;
			if( 0!=sourceGen.Finalize() )
				ret = -3;
		} else {
			ret = -3;
		}
		if( 0!=ret ) {
			cout << "Failed to generate c++ source file." << endl;
			break;
		}

		cout << "Generate complete with no error." << endl;
		break;
	}

#if 0
	::system("pause");
#endif
	return ret;
}
